package com.kdweibo.demo.activities;

import java.util.List;

import kdweibo4j.Paging;
import kdweibo4j.Status;
import kdweibo4j.Topic;
import kdweibo4j.Weibo;
import kdweibo4j.WeiboException;
import kdweibo4j.http.AccessToken;


public class TestTrends {
	Weibo weibo = AuthConstant.getInstance().getWeibo();
	String token = "a9f4eca7ded30afdbec83b1a717f8d";
	String tokenSecret = "ddbd8e3efed6d596f344403555eac9ae";
	String network = "kdweibo.cn";
	String userId = "4f705aa524ac5d300f23d4d3";
	/**
	 * 获取某人关注的话题
	 */
	public void getUserLikeTrends(){
		
		weibo.setNetwork(network);
		weibo.setOAuthConsumer(Weibo.CONSUMER_KEY, Weibo.CONSUMER_SECRET);
		weibo.setOAuthAccessToken(new AccessToken(token, tokenSecret));
		Paging page = new Paging();
		page.setCount(20);
		page.setPage(1);//从第1页开始不是第0页
		try {
			List<Topic> topics = weibo.getTrends(userId,page);
			for(int i=0;i<topics.size();i++){
				System.out.println("["+(i+1)+"], tid:"+topics.get(i).getId()+", "+topics.get(i).getName());
			}
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
    /**
     * 获取某用户关注话题数
     * @param userid  用户ID
     * 
     * @return
     * @throws WeiboException
     */
    public void getUserLikeTrendsCount(String userid) {
    	weibo.setNetwork(network);
		weibo.setOAuthConsumer(Weibo.CONSUMER_KEY, Weibo.CONSUMER_SECRET);
		weibo.setOAuthAccessToken(new AccessToken(token, tokenSecret));
		Paging page = new Paging();
		page.setCount(20);
		page.setPage(1);//从第1页开始不是第0页
		try {
			int topicsCount = weibo.getTrendsCount(userId);
				System.out.println("topicsCount:"+topicsCount);
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    /**
     * 获取某一话题下的微博
     * @param trendName 话题名称
     * 
     * @return
     * @throws WeiboException
     */
    public void getTrendsTimeline() {
    	weibo.setNetwork(network);
		weibo.setOAuthConsumer(Weibo.CONSUMER_KEY, Weibo.CONSUMER_SECRET);
		weibo.setOAuthAccessToken(new AccessToken(token, tokenSecret));
		Paging page = new Paging();
		page.setCount(20);
		page.setPage(1);//从第1页开始不是第0页
		try {
			List<Status> statuses = weibo.getTrendStatus("请插入话题名称", page);
			for(int i=0;i<statuses.size();i++){
				System.out.println("["+(i+1)+"], tid:"+statuses.get(i).id+", "+statuses.get(i).getUser().getName()+", "+statuses.get(i).getText());
			}
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
	
    //更多：周热门，最新话题，关注 取消关注某一话题，话题搜索 请参考WIKI&WSDL
    
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TestTrends testTrends = new TestTrends();
		testTrends.getUserLikeTrends();
		testTrends.getUserLikeTrendsCount(testTrends.userId);
		testTrends.getTrendsTimeline();
	}

	
}
